<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">

    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/layui/rate.js"></script>
    <link rel="stylesheet" href="/layui-v2.5.7/layui/css/layui.css"  media="all">
    <script src="/layui-v2.5.7/layui/layui.js" charset="utf-8"></script>

</head>
<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="staffUsername" class="layui-form-label">
                <span class="x-red">*</span>您的账户
            </label><br>
            <div class="layui-input-inline">
<!--                <input type="text"  id="userName" name="userName" required="" lay-verify="required"-->
<!--                       autocomplete="off" class="layui-input" placeholder="用户名">-->
                <span style="font-size: larger"  id="staffUsername" name="staffUsername"  shiro:principal property="staffUsername"/>
            </div>
        </div>
        <div class="layui-form-item layui-form-text"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div id="evaluateStar" name="evaluateStar"></div>
        </span>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">评价</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="evaluateContent" lay-verify="required"  id="evaluateContent"></textarea>
            </div>
        </div>

        <div class="layui-form-item" >
            <button  class="layui-btn" lay-filter="add" lay-submit="">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
</div>
</body>
</html>
<script>
    var evaluateStar="";
        layui.use(['rate'], function(){
        var rate = layui.rate;
    //显示文字

         rate.render({
        elem: '#evaluateStar'
        ,value: 0 //初始值
        ,text: true //开启文本
        ,choose: function star(star){
                 evaluateStar = star
             }});
    });
        //获取评论信息


    layui.use(['form','layer'],function () {
            $ = layui.jquery;
            var form = layui.form, layer = layui.layer;

            //新增
            form.on('submit(add)', function (data) {
                console.log(data);
                console.log(evaluateStar);
                $.ajax({
                    url: "/evaluate/submitAdd",
                    async: false,
                    type: "POST",
                    dataType: "json",
                    elem: '#evaluateContent',
                    data: {"evaluateContent":$("#evaluateContent").val(),"evaluateStar":evaluateStar,"staffUsername":$("#staffUsername").val()},
                    // data:data.field,
                    success: function (data) {
                        //提示信息
                        layer.alert(data.info);
                        //放入了map中，调用info
                        if (data.info == "评价成功，谢谢！") {
                            //获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新
                            parent.window.location.replace("/evaluate/pj")
                        }
                    }

                })

                return false;
            })
        })

</script>
